import { lastValueFrom } from "rxjs";
import { Injectable } from "@nestjs/common";

import { insertOneJournalRpcDto, JournalRpcInsertOnePath, JournalRpcInterfaceWithDerive, RestDto } from "qqlx-core";
import { ENUM_APP } from "qqlx-core";

import { BusRpc } from "./app.droplet-bus";
import { RpcWaiting } from "./rpc.response";
import { RpcConnection } from "./com.connection";

@Injectable()
export class JournalRpc extends RpcConnection implements JournalRpcInterfaceWithDerive<RestDto> {
  constructor(readonly BusRpc: BusRpc) {
    super(BusRpc, ENUM_APP.POND_JOURNAL);
  }

  @RpcWaiting(JournalRpcInsertOnePath)
  async insertOne(dto: RestDto & insertOneJournalRpcDto) {
    const ob = this.CLIENT.send(JournalRpcInsertOnePath, dto);
    return lastValueFrom<null>(ob);
  }
}
